package com.jz.community.moduleshoppingguide.nearshop.ui.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.bean.baseGoods.BaseGoodsInfo;
import com.jz.community.moduleshoppingguide.R;

import java.util.List;

public class StandardItemAdapter extends BaseQuickAdapter<BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX.SkuPropertiesBean.PropertyValuesBean, BaseViewHolder> {


    private BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX.SkuPropertiesBean bean;
    IChoose ichoose;

    public StandardItemAdapter(int layoutResId, @Nullable List<BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX.SkuPropertiesBean.PropertyValuesBean> data, BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX.SkuPropertiesBean bean) {
        super(layoutResId, data);
        this.bean = bean;
    }

    @Override
    protected void convert(BaseViewHolder helper, BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX.SkuPropertiesBean.PropertyValuesBean item) {
        TextView flow_text = helper.getView(R.id.flow_text);
        flow_text.setText(item.getPropertyValue());
        if (item.isChick()) {
            flow_text.setBackground(mContext.getResources().getDrawable(R.drawable.standard_item_select_back));
            flow_text.setTextColor(Color.parseColor("#ffffff"));
        } else {
            flow_text.setBackground(mContext.getResources().getDrawable(R.drawable.standard_item_back));
            flow_text.setTextColor(Color.parseColor("#333333"));
        }
        flow_text.setOnClickListener(v -> {
            bean.setCurrentChooseSkuId("");
            for (int i = 0; i < mData.size(); i++) {
                mData.get(i).setChick(false);
            }
            item.setChick(true);
            bean.setChickedOk(true);
            bean.setCurrentChooseSkuId(bean.getId() + "|" + item.getId());
            notifyDataSetChanged();
            if (ichoose != null) {
                ichoose.chooseItem();
            }
        });
    }

    public interface IChoose {
        void chooseItem();
    }

    public void setIchoose(IChoose ichoose) {
        this.ichoose = ichoose;
    }
}
